$(".navigation .floatleft .nav-title").css("color", "#000000");
var loseCount = parseInt(localStorage.loseCount);
console.log("LoseCount: ", loseCount);
var money = parseFloat($(".navigation_top .sheader_img_eggs:eq(1) .sheader_red").text().replace(/,/g, ""));
console.log("Current money: ", money);
var warnFlag = 0;
var total;
if(loseCount == 0) {
	console.log("refreshed...");
	total = Math.floor(money / 7250);
	localStorage.total = total;
}
else {
	console.log("not refreshed...");
	warnFlag = 1;
	total = parseInt(localStorage.total);
}
console.log("Total: ", total);

var remain = parseInt($("#RemainTitle span:eq(2)").text());
console.log("剩余时间：" + remain + "s");

var times = 1;

var altTimes = 1;
if(loseCount > 0) {
	if(loseCount == 1) {
		altTimes = 1;
	}
	else if(loseCount == 2) {
		altTimes = 3;
	}
	else if(loseCount == 3) {
		altTimes = 16;
	}
	else if(loseCount == 4) {
		altTimes = 100;
	}
	else if(loseCount == 5) {
		altTimes = 600;
	}
}
times = altTimes;

//刷新赔率 
var lid = window.location.href.substr(window.location.href.lastIndexOf("=")+1, 6);
var distMask = [1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1];

function refreshd() {
	$.ajax({
		type:"get",
		url:"pg28mode.aspx?refresh="+lid,
		error: function() {
		},
		success: function(data, textStatus) {
			var oddsList = data.split(",");
			console.log(oddsList);
			var sumFinal = 0;
			var invertOdds = new Array(28);
			var finalDist = [];
			for(var i = 0; i <= 27; i++) {
				if(distMask[i] > 0) {
					invertOdds[i] = 1 / parseFloat(oddsList[i]);
					sumFinal = sumFinal + invertOdds[i];
				}
			}
			for(var i = 0; i <= 27; i++) {
				if (distMask[i] > 0) {
					finalDist.push(Math.round(total * times / sumFinal * invertOdds[i]));
					$("#txt" + i).val(finalDist[i]);
				}
				else 
					finalDist.push(0);
			}
		}
	});
}

function randomg() {
	var finalDist = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
	for(var i = 0; i < 3; i++) {
		finalDist[Math.round((Math.random()*1000)%28)] = 1;
	}
	for(var i = 0; i <= 27; i++) {
		if (finalDist[i] > 0) {
			$("#txt" + i).val(finalDist[i]);
		}
	}
	localStorage.refresh = "true";
	location.href='javascript:for(var i = 0; i <= 27; i++) {$("#txt" + i).keyup().blur();};$("#conform_btn").click();$(".btnpane a").click(); void 0';
}

function randomt() {
	$.ajax({
		type:"get",
		url:"pg28mode.aspx?refresh="+lid,
		error: function() {
		},
		success: function(data, textStatus) {
			var finalDist = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
			for(var i = 0; i < 3; i++) {
				finalDist[Math.round((Math.random()*1000)%28)] = 1;
			}
			for(var i = 0; i <= 27; i++) {
				if (finalDist[i] > 0) {
					$("#txt" + i).val(finalDist[i]);
				}
			}
			localStorage.refresh = "true";
			location.href='javascript:for(var i = 0; i <= 27; i++) {$("#txt" + i).keyup().blur();};$("#conform_btn").click();$(".btnpane a").click(); void 0';
		}
	});
}

/*
var until = 15;
var before = until + 10;
if(remain > before) {
	console.log("wait to refresh...");
	setTimeout( function() {
		window.location.reload();
	}, (remain-before)*1000 );
}
else {
	console.log("wait to post...");
	setTimeout( function() {
		console.log("do random");
		randomg();
	}, 
	//t*1000
	(remain - until)*1000 );
}
*/
var t = Math.round(Math.random()*(remain - 90)+10);
console.log(t);
setTimeout( function() {
	console.log("do random");
	randomg();
}, 
t*1000 );